# -*- coding: UTF-8 -*-

from json import loads

from requests import request as http

__all__ = ['Prometheus']


class Prometheus(object):

    def __init__(self, host, port):
        self.host = host
        self.port = port
        self.respose = {"status": 1, "msg": "successful", "data": {}}
        self.query_url = ''
        self.query_range_url = '/api/v1/query_range'

    def query_range(self, promql, datatime_start, datatime_end, step='1m'):
        try:
            return loads(http("GET", f"http://{self.host}:{self.port}{self.query_range_url}",
                              params={'query': promql, 'start': datatime_start, 'end': datatime_end,
                                      'step': step}).text)
        except Exception as e:
            print(e)

        return False
